package com.polaris.live.viewmodel.login

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.requestLoading
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.constant.LiveConst
import com.polaris.live.constant.UserRankConst
import com.polaris.live.net.userService
import com.polaris.live.resp.back_resp.PartyGameResp
import com.polaris.live.resp.bean.UserRankVo
import com.polaris.live.resp.go_resp.UserRankAnonymousBean

/**
 * UserRankViewModel
 *
 * @author Created by lucas on 2023/10/16 17:10
 * @since 1.0.0
 */
class UserRankViewModel : BaseViewModel() {

    val rankAnonymousLiveData = MutableLiveData<Any>()

    val rankCharmDayLiveData = MutableLiveData<ResultState<UserRankVo>>()
    val rankCharmMonthLiveData = MutableLiveData<ResultState<UserRankVo>>()
    fun getCharmDayRank() {
        request({ userService.getDayRank() }, rankCharmDayLiveData)
    }

    fun getCharmMonthRank() {
        request({ userService.getMonthRank() }, rankCharmMonthLiveData)
    }

    val rankRichDayLiveData = MutableLiveData<ResultState<UserRankVo>>()
    val rankRichMonthLiveData = MutableLiveData<ResultState<UserRankVo>>()
    fun getRichDayRank() {
        request({ userService.getRichDayRank() }, rankRichDayLiveData)
    }

    fun getRichMonthRank() {
        request({ userService.getRichMonthRank() }, rankRichMonthLiveData)
    }

    val rankGameDayLiveData = MutableLiveData<ResultState<UserRankVo>>()
    val rankGameMonthLiveData = MutableLiveData<ResultState<UserRankVo>>()
    fun getGameDayRank() {
        request({ userService.getGameDayRank() }, rankGameDayLiveData)
    }

    fun getGameMonthRank() {
        request({ userService.getGameMonthRank() }, rankGameMonthLiveData)
    }

    val rankPartyGameDayLiveData = MutableLiveData<ResultState<UserRankVo>>()
    val rankPartyGameMonthLiveData = MutableLiveData<ResultState<UserRankVo>>()
    fun getPartyGameDay(partyGameType: Int) {
        requestLoading(
            { userService.getPartyGameDayRank(partyGameType) },
            rankPartyGameDayLiveData,
            waitTime = 0
        )
    }

    fun getPartyGameMonth(partyGameType: Int) {
        requestLoading(
            { userService.getPartyGameMonthRank(partyGameType) },
            rankPartyGameMonthLiveData,
            waitTime = 0
        )
    }

    fun rankAnonymous(anonymous: Int, rankType: Int) {
        requestLoading({ userService.rankAnonymous(UserRankAnonymousBean(anonymous, rankType)) }, {
            rankAnonymousLiveData.value = it
        })
    }

    fun getDayOrMonthType(mGameResp: PartyGameResp, isDay: Boolean): Int {
        return when (mGameResp.id) {
            LiveConst.GameType.LUDO -> if (isDay) UserRankConst.PARTY_LODO_GAME_DAY else UserRankConst.PARTY_LODO_GAME_MONTH
            LiveConst.GameType.UNNO -> if (isDay) UserRankConst.PARTY_UNO_GAME_DAY else UserRankConst.PARTY_UNO_GAME_MONTH
            LiveConst.GameType.DOMINO -> if (isDay) UserRankConst.PARTY_DOMINO_GAME_DAY else UserRankConst.PARTY_DOMINO_GAME_MONTH
            LiveConst.GameType.BLACK8 -> if (isDay) UserRankConst.PARTY_SNOOKER_GAME_DAY else UserRankConst.PARTY_SNOOKER_GAME_MONTH
            else -> if (isDay) UserRankConst.PARTY_LODO_GAME_DAY else UserRankConst.PARTY_LODO_GAME_MONTH
        }
    }

}